<template>
  <div class="user-collect">
    <!-- 头部NavBar -->
    <div class="navBarBox">
      <NavBar title="我的收藏" routerLink="/users">
        <div></div>
      </NavBar>
    </div>
    <template v-if="collectList">
      <div class="pet_list">
        <PetListItem
          v-for="item in collectList"
          :key="item.pet_id"
          :petList="item"
          @click="handlePetDetails(item.pet_id)"
        />
      </div>
    </template>
    <template v-else>
      <Empty hint="还没有收藏哦" />
    </template>
  </div>
</template>

<script>
import { ref } from "vue";
import Empty from "@/components/Empty.vue";
import NavBar from "@/components/NavBar/NavBar.vue";
import { getCollectListApi } from "@/api/user";
import PetListItem from "@/views/petTable/component/PetListItem.vue";
import { useStore } from "vuex";
import { useRouter } from "vue-router";
export default {
  name: "Collect",
  components: {
    NavBar,
    PetListItem,
    Empty,
  },
  setup() {
    const { collectList, getCollectList } = handleGetCollect();
    getCollectList();
    const router = useRouter();
    const handlePetDetails = (value) => {
      router.push(`/petTable/${value}`);
    };
    return {
      collectList,
      handlePetDetails,
    };
  },
};
// // 获取收藏列表数据
function handleGetCollect() {
  // 存储收藏列表
  const collectList = ref([]);
  const store = useStore();
  const getCollectList = () => {
    getCollectListApi(store.state.user.profile.user_id)
      .then((res) => {
        console.log(res, "收藏列表");
        collectList.value = res.data;
      })
      .catch((err) => {
        console.log(err);
      });
  };
  return {
    collectList,
    getCollectList,
  };
}

//获取人气推荐列表数据
// function handleGetCollect() {
//   console.log(111111111111111);
//   const collectList = ref([]);
//   const getCollectList = () => {
//     getCollectListApi()
//       .then((res) => {
//         console.log("res", res);
//         console.log(222222222);
//         collectList.value = res.data;
//         console.log(collectList.value, "list");
//       })
//       .catch((err) => {
//         console.log(err, "err");
//       });
//   };
//   return { collectList, getCollectList };
// }
</script>

<style lang="less" scoped>
.user-collect {
  // 头部NavBar
  .navbarBox {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 99;
    width: 100%;
    height: 2.5rem;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    background-color: #dfe5eb;
  }
  .pet_list {
    margin-top: 3rem;
    display: flex;
    flex-flow: wrap;
    // padding-bottom: 4rem;
    justify-content: space-between;
    padding: 0 0.3rem 3rem;
    // background-color: #f4f2f2;
  }
}
</style>
